using System;
using System.Collections.Generic;
using System.Text;
using Neuparts.Ordering.Core.Entities;

namespace Neuparts.Ordering.Core.Services
{
    /// <summary>
    /// The OrderService is used to manage the Order process.
    /// </summary>
    public class OrderService
    {
        /// <summary>
        /// Creates new Orders.
        /// </summary>
        /// <param name="customer">The Customer initiating the Order.</param>
        /// <returns>An Order.</returns>
        public static Order CreateOrder(Customer customer)
        {
            if (!customer.Id.HasValue)
            {
                throw new ArgumentNullException("Customer.Id", "Customer can not have null value");
            }

            Order order = new Order();
            order.Customer = customer;
            order.OrderDate = DateTime.Now;
            order.OrderDetail = new List<OrderDetail>();

            return order;
        }

        public static Order AddItem(Order order, Item item, int quantity)
        {
            OrderDetail detail = new OrderDetail();
            detail.ItemId = item.Id.Value;
            detail.Quantity = quantity;

          

            order.OrderDetail.Add(detail);
            return order;
        }

        public static Order DeleteItem(Order order, Item item)
        {
            OrderDetail detail = new OrderDetail();
            detail.ItemId = item.Id.Value;
         

            order.OrderDetail.Add(detail);
            return order;
        }
    }
}
